package com.cimctech.socketdemo.utils;

import android.util.Log;

import java.util.List;


/**
 * 异或校验
 */
public class CheckMoth {
    private static final String TAG = "CheckMoth";

    public static int getCheck(List<Byte> data) {

        int temp = 0x0000;
        for (int i = 0; i < data.size(); i++) {
            temp = temp ^ data.get(i);
        }
        if (temp < 0) {
            temp = temp + 256;
        } else {

        }
        return temp;
    }

    public static int stringCheck(String source) {
        int ch = source.charAt(0);
        for (int i = 1; i < source.length(); i++) {
            ch ^= source.charAt(i);
        }

        Log.e(TAG, "字符串的异或 运算stringCheck: " + ch);
        return ch;

    }

}
